package com.tengju.bff.interfaces.manage.crm.dealer.facade;

import com.tengju.bff.interfaces.manage.crm.dealer.vo.ExportWechatDealerInfoVO;
import com.tengju.data.domain.model.clickhouse.wechat.WechatUserInfo;
import com.tengju.data.domain.model.clickhouse.wechat.WechatUserInfoRepository;
import com.tengju.data.domain.shared.IdObject;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class WechatDealerInfoFacade {

    private final WechatUserInfoRepository wechatUserInfoRepository;

    public List<ExportWechatDealerInfoVO> list() {
        List<WechatUserInfo> wechatUserInfoList = wechatUserInfoRepository.getAll();
        return wechatUserInfoList.stream()
                .map(c -> {
                    ExportWechatDealerInfoVO vo = new ExportWechatDealerInfoVO();
                    vo.setIdCode(c.getIdCode().getValue());
                    vo.setUserName(c.getUserName());
                    vo.setStarLevel(c.getStarLevel().getDesc());
                    vo.setWechatStatus(c.getWxActivateStatus().getDesc());
                    vo.setBlStar1(c.getBlStar1Name() + Optional.ofNullable(c.getBlStar1IdCode()).map(IdObject::toString).orElse(""));
                    vo.setBlStar2(c.getBlStar1Name() + Optional.ofNullable(c.getBlStar1IdCode()).map(IdObject::toString).orElse(""));
                    vo.setBlStar3(c.getBlStar1Name() + Optional.ofNullable(c.getBlStar1IdCode()).map(IdObject::toString).orElse(""));
                    vo.setBlStar4(c.getBlStar1Name() + Optional.ofNullable(c.getBlStar1IdCode()).map(IdObject::toString).orElse(""));
                    vo.setBlEc(c.getBlEcName() + Optional.ofNullable(c.getBlEcIdCode()).map(IdObject::toString).orElse(""));
                    vo.setBlSec(c.getBlSecName() + Optional.ofNullable(c.getBlSecIdCode()).map(IdObject::toString).orElse(""));
                    return vo;
                })
                .collect(Collectors.toList());
    }
}
